package xiaochangsama.ancientkungfugeneration.procedures;

import xiaochangsama.ancientkungfugeneration.network.AncientKungfuGenerationModVariables;
import xiaochangsama.ancientkungfugeneration.init.AncientKungfuGenerationModItems;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.chat.TextComponent;

public class EquipQingGongProcedure {
	public static void execute(Entity entity) {
		if (entity == null)
			return;
		if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == AncientKungfuGenerationModItems.JIANG_HU_QING_GONG_BOOK.get()) {
			if ((entity.getCapability(AncientKungfuGenerationModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new AncientKungfuGenerationModVariables.PlayerVariables())).PlayerQingGong != 1) {
				{
					double _setval = 1;
					entity.getCapability(AncientKungfuGenerationModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.PlayerQingGong = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				if (entity instanceof Player _player)
					_player.closeContainer();
				if (entity instanceof Player _player && !_player.level.isClientSide())
					_player.displayClientMessage(new TextComponent("\u00A7l\u4F60\u88C5\u5907\u4E86\u6C5F\u6E56\u8F7B\u529F\uFF01\uFF01\uFF01"), (true));
			} else {
				if (entity instanceof Player _player)
					_player.closeContainer();
				if (entity instanceof Player _player && !_player.level.isClientSide())
					_player.displayClientMessage(new TextComponent("\u00A7l\u4F60\u5DF2\u7ECF\u88C5\u5907\u4E86\u6C5F\u6E56\u8F7B\u529F"), (true));
			}
		} else {
			if (entity instanceof Player _player)
				_player.closeContainer();
			if (entity instanceof Player _player && !_player.level.isClientSide())
				_player.displayClientMessage(new TextComponent("\u00A7l\u4F60\u5361bug\u4E86\uFF1F"), (true));
		}
	}
}
